﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Outcoder.Concurrency;

namespace Outcoder.Services.Implementation
{
	/// <summary>
	/// Rudimentary implementation of an <c>ISettingsStore</c> for storing data 
	/// that should be removed once the application exits.
	/// </summary>
	class TransientSettingsStore : ISettingsStore
	{
		Dictionary<string, object> dictionary = new Dictionary<string, object>();

		public bool TryGetValue(string key, Type settingType, out object value)
		{
			return dictionary.TryGetValue(key, out value);
		}

		public bool Contains(string key)
		{
			return dictionary.ContainsKey(key);
		}

		public bool Remove(string key)
		{
			return dictionary.Remove(key);
		}

		public Task Clear()
		{
			dictionary.Clear();

			return TaskUtility.CreateTaskWithResult();
		}

		public Task Save()
		{
			/* Nothing to do. */

			return TaskUtility.CreateTaskWithResult();
		}

		public object this[string key]
		{
			get
			{
				return dictionary[key];
			}
			set
			{
				dictionary[key] = value;
			}
		}

		public SettingsStoreStatus Status
		{
			get
			{
				return SettingsStoreStatus.Ready;
			}
		}
	}
}
